package com.general.framework.example.goodsMap;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<Goods> goodsLists = new ArrayList<>();

        goodsLists.add(new Goods("1", "商品1",1, 100));
        goodsLists.add(new Goods("2", "商品2",2, 200));
        goodsLists.add(new Goods("3", "商品3",2, 200));
        goodsLists.add(new Goods("4", "商品4",6, 100));
        goodsLists.add(new Goods("5", "商品5",6, 300));
        goodsLists.add(new Goods("6", "商品6",7, 300));


        Map<Integer, List<Goods>> goodsMap = new HashMap<>();

        for (Goods goods : goodsLists) {
            List<Goods> goodsList = goodsMap.get(goods.getGoodsType());
            if (goodsList == null) {
                goodsList = new ArrayList<>();
                goodsMap.put(goods.getGoodsType(), goodsList);
            }
            goodsList.add(goods);
        }
        Object[] objects = goodsLists.toArray();
        for (Object object : objects) {
            System.out.println(object.toString());
        }
        // System.out.println(goodsMap.toString());
    }
}
